/**
 * Created by lcfevr on 16/6/20.
 */
import Vue from 'vue';
import Vlc from 'vlc-ui'
import VueRouter from 'vue-router';
// import Vuex from 'vuex'
import App from './components/app.vue';
import Routers from './router';
import Env from './config/env';
import {setPageTitle} from './utils/util.js';
import Config from './config/config'
import Axios from 'axios';
import store from './datas/store';
import Request from './utils/request'
import * as filters from './utils/filters';
import {Cache, cache_keys } from './utils/util';
Vue.use(VueRouter);
Vue.use(Vlc);
// 开启debug模式
Vue.config.debug = true;

Vue.prototype.$Config = Config;
Vue.prototype.$Request = Request;
Vue.prototype.$http = Axios;
// console.log(this.$http);
// 路由配置
Object.keys(filters).forEach(name => {
  Vue.filter(name, filters[name]);
});
let router = new VueRouter({

    history: Env != 'production',
    routes:Routers
});


router.beforeEach((to,from,next) => {
    let title = to.meta.title || Config.doc_title;
    setPageTitle(title);

    window.scrollTo(0, 0);
  if (to.meta.authorization) {
    var target = {name: to.meta.login || 'login-quick', query: {source: to.path}};
    var oauth = Cache.get(cache_keys.token);
    oauth ? next() : next(target);
  } else {
    next();
  }

});

router.afterEach(() => {

});

window.EventBus = new Vue();

new Vue({
    el: '#app',
    store,
    router: router,
    render: h => h(App)
})
